/**
 * @description 创建 node 客户端，浏览器请求的服务端
 * @author xfj
 */

const http = require('http')

const serverHandler = (request, response) => {
  // 创建 node 客户端
  const option = {
    port: 1234,
    method: 'POST',
  }
  const req = http.request(option, (res) => {
    let data = ''
    res.on('data', (chunk) => {
      data += chunk
    })
    res.on('end', () => {
      response.end(data)
    })
  })

  // 将数据写入请求正文
  req.end(JSON.stringify({name: 'xfj', age: 24}))
}

// 创建服务端
const server = http.createServer(serverHandler)

server.listen(8080, () => {
  console.log('代理服务运行在 8080 端口...')
})
